# -*- coding: utf-8 -*-
from __future__ import absolute_import
import logging

from celery.utils.log import get_task_logger
from celery import shared_task, task


from . import dao

# logger = logging.getLogger('blog')
logger = get_task_logger(__name__)
# @shared_task
# def add(x, y):
#     return x + y
#
#
# @shared_task
# def mul(x, y):
#     return x * y
#
#
# @shared_task
# def xsum(numbers):
#     return sum(numbers)


# @shared_task
# def save_article(site,article):
#     return dao.save_article(site,article)
@task
def save_article_task(site_id,article):
    dao.save_article(site_id,article)
# class FeedImporter(Task):
#     name = "feed.import"
#     routing_key = 'feed.import'
#     ignore_result = True
#     default_retry_delay = 5*60
#     max_retries = 72
#     def run(self,podcast_id, **kwargs):
#         try:
#             logger = self.get_logger(**kwargs)
#         except Exception as exc:
#             logger.error(exc)


@task
def ready_cron():
    """
    找到刚加入的cron,获取其总页数,然后修改为准备状态
    """
    import datetime
    logger.debug('ready cron')
    f = open('a.txt','a+')
    f.write(str(datetime.datetime.now()))
    f.write('\n')
    f.close()
@task
def handle_cron():
    """
    find ready cron, execute one
    """
    import datetime
    logger.debug('ready cron')
    f = open('b.txt','a+')
    f.write(str(datetime.datetime.now()))
    f.write('\n')
    f.close()
